/**
 * LS_AckPacket.java
 *
 * @author Hagen Boehm
 */


package SSF.OS.OSPFv2;


import java.util.Vector;
import java.util.Enumeration;
import SSF.OS.ProtocolMessage;


// ========================= class SSF.OS.OSPFv2.LS_AckPacket ============================ //
/**
 * This class implements an OSPF Acknowledgment Packet. The following from RFC2328 was
 * not included:
 * 1.) Version
 * 2.) Packet length
 * 3.) Checksum
 * 4.) Authentication 
 */
public class LS_AckPacket extends ProtocolMessage {

  public Vector lsaHeaders;

  // ----------------------------- constructor LS_AckPacket ---------------------------- //

  public LS_AckPacket() {
    lsaHeaders = new Vector();
  }

  // -------------------------------- LS_AckPacket.put --------------------------------- //
  /** 
   *  append an LSA Header to this LS Acknowledgment Packet payload.
   */
  public void put(LSA lsa) {
    if (lsa.payload() != null)
      lsa.dropPayload();
    lsaHeaders.add(lsa);
  }

  // ----------------------------- LS_AckPacket.getHeaders ----------------------------- //
  /**
   *  return a Vector of all LSA Headers contained in this LS Acknowledgment Packet payload.
   */
  public Vector getHeaders() {
    return lsaHeaders;
  }

  // ----------------------------- LS_AckPacket.carryPayload ---------------------------- //

  public void carryPayload(ProtocolMessage payload) {
    System.err.println("** Warning: LS_AckPacket can't take payload; dropping.");
  }

  // ------------------------------- LS_AckPacket.bytecount ---------------------------- //
  /** Return the total size (in bytes) of this LS Acknowledgment Packet body. 
   *  All and only fields specified in RFC 2328 are included in calculation!!!
   */
  public int bytecount(){
    return header_bytecount();
  }

  // ---------------------------- LS_AckPacket.header_bytecount ------------------------- //
  /** Return the size (in bytes) of this header only, don't include a payload. 
   *  Link State Acknowledgment Packets don't have payload.
   */
  public int header_bytecount(){
    return (lsaHeaders.size() * LSA.headerByteCount());
  }

  // ---------------------------- LS_AckPacket.toString -------------------------- //
  public String toString() {
    String s = "";
    for (Enumeration e = lsaHeaders.elements() ; e.hasMoreElements() ;) {
              s += e.nextElement().toString() + " ";

          }  
    return s;
  }

} //end class LS_AckPacket
